# INSTALL and SOURCE_GROUP commands for OSG/OT/Producer Modules

# Required Vars:
# ${LIB_NAME}
# ${LIB_PUBLIC_HEADERS}

SET(INSTALL_INCDIR include)
SET(INSTALL_BINDIR bin)
IF(WIN32)
    SET(INSTALL_LIBDIR bin)
    SET(INSTALL_ARCHIVEDIR lib)
ELSE(WIN32)
    SET(INSTALL_LIBDIR lib${LIB_POSTFIX})
    SET(INSTALL_ARCHIVEDIR lib${LIB_POSTFIX})
    SET(INSTALL_FRAMEWORKDIR Frameworks)
ENDIF(WIN32)

SET(HEADERS_GROUP "Header Files")

SOURCE_GROUP(
    ${HEADERS_GROUP}
    FILES ${LIB_PUBLIC_HEADERS}
)

IF(MSVC AND OSG_MSVC_VERSIONED_DLL)
	HANDLE_MSVC_DLL()
ENDIF(MSVC AND OSG_MSVC_VERSIONED_DLL)

if (APPLE)
   set(CMAKE_INSTALL_RPATH "${DELTA3D_FRAMEWORK_INSTALL_NAME_DIR}")

   if (DELTA3D_ALLOW_FRAMEWORK AND DELTA3D_COMPILE_FRAMEWORKS AND DELTA3D_FRAMEWORK_INSTALL_NAME_DIR)
      SET_TARGET_PROPERTIES(${LIB_NAME} PROPERTIES
         FRAMEWORK TRUE
         FRAMEWORK_VERSION A 
         PUBLIC_HEADER  "${LIB_PUBLIC_HEADERS}"
         INSTALL_NAME_DIR "${DELTA3D_FRAMEWORK_INSTALL_NAME_DIR}"
         LIBRARY_OUTPUT_DIRECTORY "${CMAKE_FRAMEWORK_OUTPUT_DIRECTORY}"
      )
   else()
      if (DELTA3D_DYLIB_INSTALL_NAME_DIR)
         SET_TARGET_PROPERTIES(${LIB_NAME} PROPERTIES
            INSTALL_NAME_DIR "${DELTA3D_DYLIB_INSTALL_NAME_DIR}"
         )
      else()
         set(CMAKE_INSTALL_RPATH "${INSTALL_INCDIR}/${LIB_NAME}")
         SET_TARGET_PROPERTIES(${LIB_NAME} PROPERTIES
            INSTALL_NAME_DIR "${INSTALL_INCDIR}/${LIB_NAME}"
         )
      endif()      
   endif()   
endif()

INSTALL (
   FILES        ${LIB_PUBLIC_HEADERS}
   DESTINATION  ${INSTALL_INCDIR}/${LIB_NAME}
   COMPONENT delta3d-dev
)
INSTALL(
  TARGETS ${LIB_NAME}
  RUNTIME DESTINATION ${INSTALL_BINDIR} COMPONENT delta3d
  LIBRARY DESTINATION ${INSTALL_LIBDIR} COMPONENT delta3d
  FRAMEWORK DESTINATION ${INSTALL_FRAMEWORKDIR} COMPONENT delta3d
  ARCHIVE DESTINATION ${INSTALL_ARCHIVEDIR} COMPONENT delta3d-dev
)
